
<?
	  include("/inc/header.html") {}
    ?>    
    
            
                            <div class="panel panel" >          
                                <div class="panel-body pan"  >
                                        <div class="form-body pal" >
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                     <label for="inputUsername" >中文名称 <span class='require'>*</span> </label>
                                                        <div class="input-icon right">
                                                            <input id="nameZh" type="text" class="form-control" onchange="pinYin(this.value)"/>
                                                        </div>
                                                    </div>
                                                </div>
                                                 <div class="col-md-6">
                                                    <div class="form-group">
                                                     <label for="inputUsername" >英文名称 <span class='require'>*</span> </label>
                                                        <div class="input-icon right">
                                                          <input id="nameEn" type="text" class="form-control" onchange="voluation(this.value);"/>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <div class="input-icon right">   
                                                         <label for="inputUsername" >字段名称 <span class='require'>*</span> </label>
                                                            <input id="field" type="text" class="form-control" readonly="readonly" />
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <div class="input-icon right">
                                                         <label for="inputUsername" >排序 <span class='require'>*</span> </label>
                                                            <input id="sort" type="text" class="form-control" />
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <hr/>
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group"><label for="inputUsername" >数据类型   <span class='require'>*</span></label>
                                                        <select  id="dataTypeid"  class="form-control" onchange="gradeChange()">
                                                            <option value="00">--请选择--</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                
                                                <div class="col-md-6">
                                                    <div class="form-group"><label for="inputUsername" >关联字典类  </label>
                                                        <select id="dict" class="form-control">
                                                            <option value="00">--请选择--</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <div class="input-icon right">
                                                         <label for="inputUsername" >字段长度 <span class='require'>*</span> </label>
                                                            <input id="fieldLength" type="text" class="form-control" />
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                                 <hr/>
                                              <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group"><label for="inputUsername" >是否多值 <span class='require'>*</span> </label>
                                                        <select  id="multiValued"  class="form-control">
                                                             <option value="0">false</option>
                                                             <option value="1">true</option>
                                                        </select>    
                                                    </div>                                                   
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group"><label for="inputUsername" >是否必填 <span class='require'>*</span> </label>
                                                        <select  id="required"  class="form-control">
                                                             <option value="0">false</option>
                                                             <option value="1">true</option>
                                                        </select>    
                                                    </div>                                                   
                                                </div>
                                                 <div class="col-md-6">
                                                    <div class="form-group"><label for="inputUsername" >是否内容存储 <span class='require'>*</span> </label>
                                                        <select  id="stored"  class="form-control">
                                                        	<option value="1">true</option>
                                                             <option value="0">false</option>
                                                        </select>    
                                                    </div>                                                   
                                                </div>
                                                 <div class="col-md-6">
                                                    <div class="form-group"><label for="inputUsername" >是否建立索引<span class='require'>*</span> </label>
                                                        <select  id="indexed"  class="form-control">
                                                        	<option value="1">true</option>
                                                             <option value="0">false</option>
                                                        </select>    
                                                    </div>                                                   
                                                </div>
                                                 <div class="col-md-6">
                                                    <div class="form-group"><label for="inputUsername" >是否用作特性 <span class='require'>*</span> </label>
                                                        <select  id="termVectors"  class="form-control">
                                                             <option value="0">false</option>
                                                             <option value="1">true</option>
                                                        </select>    
                                                    </div>                                                   
                                                </div>
                                            </div>
                                             <hr/>
                                              <div class="row">
                                              	<div class="col-md-6">
                                                    <div class="form-group"><label for="inputUsername" >是否分面字段<span class='require'>*</span> </label>
                                                        <select  id="faceted"  class="form-control">
                                                             <option value="0">false</option>
                                                             <option value="1">true</option>
                                                        </select>    
                                                    </div>                                                   
                                                </div>
                                                 <div class="col-md-6">
                                                    <div class="form-group"><label for="inputUsername" >是否普通检索字段 <span class='require'>*</span> </label>
                                                        <select  id="generalSearchField"  class="form-control">
                                                             <option value="0">false</option>
                                                             <option value="1">true</option>
                                                        </select>    
                                                    </div>                                                   
                                                </div>
                                                 <div class="col-md-6">
                                                    <div class="form-group"><label for="inputUsername" >是否高级检索字段<span class='require'>*</span> </label>
                                                        <select  id="advancedSearchField"  class="form-control">
                                                             <option value="0">false</option>
                                                             <option value="1">true</option>
                                                        </select>    
                                                    </div>                                                   
                                                </div>
                                                 <div class="col-md-6">
                                                    <div class="form-group"><label for="inputUsername" >是否二次检索字段<span class='require'>*</span> </label>
                                                        <select  id="searchWithinResultsField"  class="form-control">
                                                             <option value="0">false</option>
                                                             <option value="1">true</option>
                                                        </select>    
                                                    </div>                                                   
                                                </div>
                                                 <div class="col-md-6">
                                                    <div class="form-group"><label for="inputUsername" > 是否标红字段<span class='require'>*</span> </label>
                                                        <select  id="highlightingField"  class="form-control">
                                                             <option value="0">false</option>
                                                             <option value="1">true</option>
                                                        </select>    
                                                    </div>                                                   
                                                </div>
                                              </div>
                                                <hr/>
                                              <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group"><label for="inputUsername" >是否产品库普通检索字段<span class='require'>*</span> </label>
                                                        <select  id="productGeneralSearchField"  class="form-control">
                                                             <option value="0">false</option>
                                                             <option value="1">true</option>
                                                        </select>    
                                                    </div>                                                   
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group"><label for="inputUsername" >是否产品库高级检索字段<span class='require'>*</span> </label>
                                                        <select  id="productAdvancedSearchField"  class="form-control">
                                                             <option value="0">false</option>
                                                             <option value="1">true</option>
                                                        </select>    
                                                    </div>                                                   
                                                </div>
                                               </div>
                                        </div>
                                     
                                </div>
                            </div>   


<script>
	var index1 = window.parent.getlay();
	$(function() {
		dataTypedata();
		document.getElementById('dict').disabled = true;
	});
	//字典下拉
	function dictdata() {
			$.ajax({
			type : "post",
			url : "./DictListall.do",
			data : {},
			dataType : "json",
			success : function(data) {
				$(data).each(
						function(n) {
							$("<option/>").html(data[n].nameZh).val(data[n].id)
									.appendTo("#dict");
						});
				if (index1 != 0 ) {
					demo1();
				}
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}

	//数据属性下拉
	function dataTypedata() {
		$.ajax({
			type : "post",
			url : "./KnowledgeListall.do",
			data : {},
			dataType : "json",
			success : function(data) {
				$(data).each(
						function(n) {
							$("<option/>").html(data[n].nameZh).val(data[n].id)
									.appendTo("#dataTypeid");
						});
					dictdata();
			},
			error : function(data) {
				alert("请求失败");
			}
		});
		//$("#dataTypeid").find("value").remove();
	}

	function Page() {

		if ($.trim($("#sort").val()).length < 1) {
			alert('排序不能为空！');
			return null;
		}
		if (isNaN($("#sort").val())) {
			alert("必须是数字");
			return null;
		}

		if ($.trim($("#fieldLength").val()).length < 1) {
			alert('排序不能为空！');
			return null;
		}
		if (isNaN($("#fieldLength").val())) {
			alert("必须是数字");
			return null;
		}
		$.ajax({
			type : "post",
			url : "./KnowledgeCommonDatasave.do",
			data : {
				"id" : index1,
				"nameEn" : $("#nameEn").val(),
				"nameZh" : $("#nameZh").val(),
				"sort" : $("#sort").val(),
				"fieldLength" : $("#fieldLength").val(),
				"dataType" : $("#dataTypeid").val(),
				"dict" : $("#dict").val(),
				"field" : $("#field").val(),
				"multiValued" : $("#multiValued").val(),
				"required" : $("#required").val(),
				"stored" : $("#stored").val(),
				"indexed" : $("#indexed").val(),
				"termVectors" : $("#termVectors").val(),
				"faceted" : $("#faceted").val(),
				"generalSearchField" : $("#generalSearchField").val(),
				"advancedSearchField" : $("#advancedSearchField").val(),
				"searchWithinResultsField" : $("#searchWithinResultsField").val(),
				"highlightingField" : $("#highlightingField").val(),
				"productGeneralSearchField" : $("#productGeneralSearchField").val(),
				"productAdvancedSearchField" : $("#productAdvancedSearchField").val(),
			},
			dataType : "json",
			async : false,
			success : function(data) {
				var index = parent.layer.getFrameIndex(window.name);
				window.parent.get();
				parent.layer.msg('添加或编辑成功');
				parent.layer.close(index);
			},
			error : function(data) {
				alert("请求失败");
			}
		});

	}

	function demo1() {
		$.getJSON('./KnowledgeCommonDataedit.do',
				{
					id : index1
				//向服务端传的参数，此处只是演示
				}, function(res) {
					//alert(JSON.stringify(res));
					//此处仅仅是为了演示变化的内容
					$("#nameEn").val(res[0].nameEn);
					$("#nameZh").val(res[0].nameZh);
					$("#sort").val(res[0].sort);
					$("#field").val(res[0].field);
					$("#fieldLength").val(res[0].fieldLength);
					selected("multiValued", res[0].multiValued);
					selected("required", res[0].required);
					selected("stored", res[0].stored);
					selected("indexed", res[0].indexed);
					selected("termVectors", res[0].termVectors);
					selected("dataTypeid", res[0].dataTypeId);
					selected("dict", res[0].dictId);
					selected("faceted", res[0].faceted);
					selected("generalSearchField", res[0].generalSearchField);
					selected("advancedSearchField", res[0].advancedSearchField);
					selected("searchWithinResultsField", res[0].searchWithinResultsField);
					selected("highlightingField", res[0].highlightingField);
					selected("productGeneralSearchField", res[0].productGeneralSearchField);
					selected("productAdvancedSearchField", res[0].productAdvancedSearchField);
					document.getElementById('nameEn').disabled = true;
					document.getElementById('dataTypeid').disabled = true;
					if(res[0].dataTypeId == 4 || res[0].dataTypeId == 5 || res[0].dataTypeId == 6){
						document.getElementById('fieldLength').disabled = true;
					}
				});
	};
	function selected(selectname, selectid) {
		$("#" + selectname + " option").each(function() { //遍历全部option
			var v = $(this).val(); //获取option的内容
			if (v == selectid) {
				$(this).attr("selected", "selected");
			}
		});
	}
	function voluation(name) {
		if ($.trim(name).length < 1) {
			alert('英文名不能为空！');
			return null;
		}
		if ($.trim(name).length > 32) {
			alert('英文名长度过长！');
			$("#nameEn").val("");
			$("#field").val("");
			return null;
		}
		$.ajax({
			type : "post",
			url : "./KnowledgeCommonDataPropertyProving.do",
			data : {
				"name" : name,
			},
			async : false,
			dataType : "json",
			success : function(data) {
				if (data.result != 1) {
					alert("表名不可用，重命名或者不符合规则");
					$("#nameEn").val("");
				}

			},
			error : function(data) {
				alert("请求失败");
			}
		});
  $("#field").val($("#nameEn").val());
	}
	//二级联动
	function gradeChange() {
		var objS = document.getElementById("dataTypeid");
		var gradeid = objS.options[objS.selectedIndex].value;
		if(gradeid==10||gradeid==9){
		$("#fieldLength").val("11");
			document.getElementById('fieldLength').disabled = true;
		}else if(gradeid==5||gradeid==6||gradeid==4)
		{
		$("#fieldLength").val("0");
		document.getElementById('fieldLength').disabled = true;
		}else
		{
			$("#fieldLength").val("");
			document.getElementById('fieldLength').disabled = false;
		}
		
		if(gradeid=="7" || gradeid=="20"){
			document.getElementById('dict').disabled = false;
		}else{
			$("#dict").val("00");
			document.getElementById('dict').disabled = true;
		}
	}
	
	//汉字转拼音
  function pinYin(pinyinName){
 	 if (index1 == 0 ) {
		$.ajax({
			type : "post",
			url : "hanziToinitial.do",
			data : {
				"pinYin" : pinyinName,
			},
			async : false,
			dataType : "json",
			success : function(data) {
				if(data[0].length > 32){
					layer.msg('自动转换英文名长度过长!请手动输入！');
					$("#nameEn").val("");
					$("#field").val("");
				}else{
					$("#nameEn").val(data);
					$("#field").val(data);
				}
			},
			error : function(data) {
				alert("请求失败");
			}
		});
		}
	}
</script>


